package org.syntaxlisp.core;

import org.syntaxlisp.core.element.SyntaxLispElement;
import org.syntaxlisp.core.match.MatchUnit;

import java.util.*;


public class ErrorParseException extends ParseException {

    private Set<SyntaxLispElement> missingMatchElements;

    public ErrorParseException(MatchUnit unexpected, Collection<SyntaxLispElement> missingMatchTargets) {
        super(consMsg(unexpected, missingMatchTargets));
        missingMatchElements = new HashSet<>(missingMatchTargets);
    }

    private static String consMsg (MatchUnit unexpected, Collection<SyntaxLispElement> missingMatchTargets) {
        StringBuilder errMsg = new StringBuilder("Unexpected input found: " + unexpected.toString() +
                                                 ", while expected: ");
        for (SyntaxLispElement missingMatch : missingMatchTargets) {
            errMsg.append(missingMatch.toErrMsgString()).append(" ");
        }
        return errMsg.append(".").toString();
    }
}
